home *** CD-ROM | disk | FTP | other *** search
-
- #pragma segment EVENT
-
- /*
- ** This source code was written by Tim Endres
- ** Email: time@ice.com.
- ** USMail: 8840 Main Street, Whitmore Lake, MI 48189
- **
- ** Some portions of this application utilize sources
- ** that are copyrighted by ICE Engineering, Inc., and
- ** ICE Engineering retains all rights to those sources.
- **
- ** Neither ICE Engineering, Inc., nor Tim Endres,
- ** warrants this source code for any reason, and neither
- ** party assumes any responsbility for the use of these
- ** sources, libraries, or applications. The user of these
- ** sources and binaries assumes all responsbilities for
- ** any resulting consequences.
- */
-
- #include "tickle.h"
- #include "tge.h"
- #include "tclMac.h"
-
- #include <EPPC.h>
- #include <AppleEvents.h>
-
-
- static int yield_ticks = 0;
-
- pausing()
- {
- yield_ticks = 30;
- DoYield();
- yield_ticks = 0;
- }
-
- static int UYieldDepth = 0;
-
- UBegYield()
- {
- if (UYieldDepth++ == 0)
- {
- yielding_on = 1;
- #ifdef TCLAPPL
- yield_menus(YIELD_ON);
- #endif
- }
- }
-
- UEndYield()
- {
- if (--UYieldDepth == 0)
- {
- yielding_on = 0;
- #ifdef TCLAPPL
- yield_menus(YIELD_OFF);
- #endif
- }
- }
-
- extern int _ctb_is_available_;
-
- DoYield()
- {
- int got_event;
- short emask;
- WindowPtr whichwindow, frontwindow;
-
- frontwindow = FrontWindow();
-
- if (_ctb_is_available_)
- Tcl_CTBIdleChecks();
-
- /* emask = osMask | activMask | updateMask | mDownMask | keyDownMask; */
- emask = ( everyEvent & ~(autoKeyMask) );
-
- if (has_wait_next_event)
- {
- got_event = WaitNextEvent(emask, &gEvent, 0, (RgnHandle)0);
- }
- else
- {
- SystemTask();
- got_event = GetNextEvent(emask, &gEvent);
- }
-
- /*
- ** Has the user done something?
- */
- if (got_event)
- {
- switch (gEvent.what)
- {
- case mouseDown:
- switch (FindWindow(gEvent.where, &whichwindow))
- {
- case inMenuBar:
- #ifdef TCLAPPL
- InitCursor();
- do_command(MenuSelect(gEvent.where));
- WatchCursorOn();
- #endif
- break;
- case inDrag:
- DragWindow(whichwindow, gEvent.where, &qd.screenBits.bounds);
- break;
- case inGoAway:
- if (frontwindow != whichwindow)
- SelectWindow(whichwindow);
- break;
- case inGrow:
- if (frontwindow == whichwindow)
- wind_parse(whichwindow, &gEvent, wGrow);
- else
- SelectWindow(whichwindow);
- break;
- case inSysWindow:
- SystemClick(&gEvent, whichwindow);
- break;
- case inContent:
- if (frontwindow != whichwindow)
- SelectWindow(whichwindow);
- break;
- }
- gLastDown = gEvent.when;
- break;
- case keyDown:
- #ifdef TCLAPPL
- if ((gEvent.modifiers & 0x0100) != 0) /* APPLE key was down also. */
- do_command(MenuKey((char)gEvent.message));
- #endif
- break;
- case activateEvt:
- wind_parse((WindowPtr) gEvent.message, &gEvent, wActivate);
- break;
- case updateEvt:
- wind_parse((WindowPtr) gEvent.message, &gEvent, wUpdate);
- break;
- case MFOSEvent:
- switch ((gEvent.message >> 24) & 0x00FF) /* high byte of message */
- {
- case MFSuspendResumeMessage:
- /* suspend/resume is also an activate/deactivate! */
- in_back_ground =
- ( (gEvent.message & MFResumeMask) == 0 );
- if (! in_back_ground)
- {
- /* RESUME */
- UResumeWindows();
- #ifdef TCLAPPL
- TEFromScrap();
- #endif
- WatchCursorOn();
- }
- else
- {
- /* SUSPEND */
- USuspendWindows();
- UInitCursor();
- }
- break;
- }
- break;
- default:
- break;
- }
-
- gLastEvent = gEvent;
- }
-
- }
-
- static short unset_script_flag = 0;
-
- PreMenuProcessing(modifiers)
- int modifiers;
- {
- menu_modifiers = modifiers;
- if ((menu_modifiers & shiftKey) != 0)
- {
- SetItem(file_menu_hdl, new_item, "\pNew Global...");
- SetItem(file_menu_hdl, open_item, "\pOpen Global...");
- unset_script_flag = 1;
- }
- }
-
- PostMenuProcessing()
- {
- if (unset_script_flag)
- {
- SetItem(file_menu_hdl, new_item, "\pNew...");
- SetItem(file_menu_hdl, open_item, "\pOpen...");
- unset_script_flag = 0;
- }
- }
-
- /*
- ** This is the standard Macintosh Event Loop. Every Macintosh application
- ** spins on this loop, waiting for the user to do something. This drives
- ** the rest of the code by responding to the user's events (mouse clicks,
- ** menu picks, keyboard inputs, etc.
- */
- do_event()
- {
- int got_event;
- #ifdef TCLAPPL
- WindowPtr whichwindow, frontwindow;
-
- /* if (gHTE != NULL) TEIdle(gHTE); */
-
- frontwindow = FrontWindow();
-
- if (frontwindow != NULL)
- if (((WindowPeek) frontwindow)->windowKind == tgeWKind)
- tge_idle(frontwindow);
-
- CheckCursor();
- #endif
-
- if (_ctb_is_available_)
- Tcl_CTBIdleChecks();
-
- /*
- ** Has the user done something?
- */
- if (has_wait_next_event)
- {
- got_event = WaitNextEvent(everyEvent, &gEvent, 13, (RgnHandle)0);
- }
- else
- {
- SystemTask();
- got_event = GetNextEvent(everyEvent, &gEvent);
- }
-
- if (got_event) {
- switch (gEvent.what) {
- /*
- ** The mouse button was pressed.
- */
- case mouseDown:
- #ifdef TCLAPPL
- switch (FindWindow(gEvent.where, &whichwindow)) {
- /*
- ** The mouse button was pressed in the menu bar.
- */
- case inMenuBar:
- InitCursor();
- PreMenuProcessing(gEvent.modifiers);
- do_command(MenuSelect(gEvent.where));
- PostMenuProcessing();
- break;
- /*
- ** The mouse button was pressed in a window title bar.
- */
- case inDrag:
- dragrect = qd.screenBits.bounds;
- dragrect.top += 20;
- InsetRect(&dragrect, 4, 4);
- DragWindow(whichwindow, gEvent.where, &dragrect);
- break;
- /*
- ** The mouse button was pressed in a window "go away" box.
- */
- case inGoAway:
- if (TrackGoAway(whichwindow, gEvent.where))
- wind_parse(whichwindow, &gEvent, wClose);
- break;
- /*
- ** The mouse button was pressed in the grow box.
- */
- case inGrow:
- if (frontwindow == whichwindow)
- wind_parse(whichwindow, &gEvent, wGrow);
- else
- SelectWindow(whichwindow);
- break;
- case inZoomIn:
- if (TrackBox(whichwindow, gEvent.where, inZoomIn))
- if (frontwindow == whichwindow)
- wind_parse(whichwindow, &gEvent, wZoomIn);
- else
- SelectWindow(whichwindow);
- break;
- case inZoomOut:
- if (TrackBox(whichwindow, gEvent.where, inZoomOut))
- if (frontwindow == whichwindow)
- wind_parse(whichwindow, &gEvent, wZoomOut);
- else
- SelectWindow(whichwindow);
- break;
- /*
- ** The mouse button was pressed in a Desk Accessory window.
- */
- case inSysWindow:
- SystemClick(&gEvent, whichwindow);
- break;
- /*
- ** The mouse button was pressed in the window contents area.
- */
- case inContent:
- if (frontwindow == whichwindow)
- wind_parse(whichwindow, &gEvent, wContent);
- else SelectWindow(whichwindow);
- break;
- }
- gLastDown = gEvent.when;
- #endif
- break;
- /*
- ** A key was pressed on the keyboard.
- */
- case keyDown:
- case autoKey:
- #ifdef TCLAPPL
- /*
- ** Check to see if it is a menu equivalent key (apple-key).
- */
- if ((gEvent.modifiers & 0x0100) != 0
- && (gEvent.message & 255) != 0x0D)
- { /* APPLE key was down also (and not Return). */
- menu_modifiers = gEvent.modifiers;
- do_command(MenuKey((char)gEvent.message));
- }
- else {
- if (macplus_keybd) {
- #ifdef NEVER_DEFINED
- According to Tech Note 168(?):
- Key ADB NON-ADB
- ---- --- -------
- left arrow $7B $46
- right arrow $7C $42
- down arrow $7D $48
- up arrow $7E $4D
- keypad plus sign (+) $45 $46 (with Shift bit set in modifiers)
- keypad asterisk (*) $43 $42 (with Shift bit set in modifiers)
- keypad equal sign (=) $51 $48 (with Shift bit set in modifiers)
- keypad slash (/) $4B $4D (with Shift bit set in modifiers)
- #endif
- switch ((gEvent.message & keyCodeMask) >> 8) {
- case 0x46:
- if ((gEvent.modifiers & shiftKey) == 0)
- gEvent.message = (gEvent.message & ~keyCodeMask) | 0x00007B00;
- break;
- case 0x42:
- if ((gEvent.modifiers & shiftKey) == 0)
- gEvent.message = (gEvent.message & ~keyCodeMask) | 0x00007C00;
- break;
- case 0x48:
- if ((gEvent.modifiers & shiftKey) == 0)
- gEvent.message = (gEvent.message & ~keyCodeMask) | 0x00007D00;
- break;
- case 0x4D:
- if ((gEvent.modifiers & shiftKey) == 0)
- gEvent.message = (gEvent.message & ~keyCodeMask) | 0x00007E00;
- break;
- }
- }
-
- wind_parse(frontwindow, &gEvent, wKeyDown);
- }
- /* gLastKey = gEvent.when; */
- #endif
- break;
- case activateEvt:
- wind_parse((WindowPtr) gEvent.message, &gEvent, wActivate);
- break;
- case updateEvt:
- wind_parse((WindowPtr) gEvent.message, &gEvent, wUpdate);
- break;
- case MFOSEvent:
- switch ((gEvent.message >> 24) & 0x00FF) { /* high byte of message */
- case MFSuspendResumeMessage: /* suspend/resume is also an activate/deactivate */
- in_back_ground = (gEvent.message & MFResumeMask) == 0;
- if (! in_back_ground) {
- /* RESUME */
- UResumeWindows();
- #ifdef TCLAPPL
- TEFromScrap();
- #endif
- UInitCursor();
- }
- else {
- /* SUSPEND */
- USuspendWindows();
- UInitCursor();
- }
- break;
- }
- break;
- case kHighLevelEvent:
- DoHighLevelEvent(&gEvent);
- break;
- }
-
- gLastEvent = gEvent;
- }
-
- if (g_cron_interval > 0)
- {
- if (g_interp != (Tcl_Interp *)0 && TickCount() > g_next_cron_time)
- {
- PFI saveproc;
- int result, tcl_dev_null_output();
- char *command =
- "if [info exists env(CRON_EXPR)] then { catch {eval \"$env(CRON_EXPR)\"} };\n" ;
-
- saveproc = Tcl_SetPrintProcedure(tcl_dev_null_output);
-
- result = Tcl_Eval(g_interp, command, 0, (char **)0);
-
- Tcl_SetPrintProcedure(saveproc);
-
- while (g_next_cron_time < TickCount()) /* CATCH UP!! */
- g_next_cron_time += g_cron_interval;
-
- UInitCursor();
- }
- }
- }
-
- wind_parse(myWindow, myEvent, wAction)
- WindowPtr myWindow;
- EventRecord *myEvent;
- int wAction;
- {
- PFI handler;
- if (checkmywindow(myWindow)) {
- handler = (PFI) GetWRefCon(myWindow);
- /* Call the window's routine stored in refcon. */
- if (handler != (PFI) 0)
- (*handler) (myWindow, myEvent, wAction);
- }
- }
-
- checkmywindow(myWindow)
- WindowPeek myWindow;
- {
- /* This function is used to check that the window asked to perform
- ** the event was created by this application.
- */
- return (myWindow->windowKind == tgeWKind)
- || (myWindow->windowKind == feedbackWKind)
- || (myWindow->windowKind == progressWKind);
- }
-
- CheckCursor()
- {
- GrafPtr saveport;
- WindowPtr myWindow, fWindow;
- Point cursorpt;
- Rect myrect;
- int want_ibeam = 0, in_front = 0;
-
- if (in_back_ground)
- return;
-
- GetPort(&saveport);
- fWindow = FrontWindow(); /* Be sure to check others' windows! */
- if (! in_front && fWindow != NULL) {
- if (! checkmywindow(fWindow)) {
- myrect = fWindow->portRect;
- SetPort(fWindow);
- GetMouse(&cursorpt);
- if (PtInRect(cursorpt, &myrect))
- in_front = 1;
- }
- }
- SetPort(saveport);
-
- myWindow = FrontWindow();
- if (! in_front && myWindow != NULL) {
- /*
- ** If the cursor is inside the front window, select on window type
- ** and set cursor accordingly, otherwise, UInitCursor().
- */
-
- /* These cover many cases... */
- myrect = myWindow->portRect;
- myrect.right -= 15;
- myrect.bottom -= 15;
-
- GetPort(&saveport);
- SetPort(myWindow);
-
- GetMouse(&cursorpt);
-
- switch (WPeek->windowKind) {
- case tgeWKind:
- if (PtInRect(cursorpt, &myrect))
- want_ibeam = 1;
- break;
- default:
- break;
- }
-
- SetPort(saveport);
- }
-
- if (! in_front && want_ibeam) {
- if (! cursor_ibeam) {
- cursor_ibeam = 1;
- SetCursor(*GetCursor(iBeamCursor));
- }
- }
- else {
- if (cursor_ibeam) {
- cursor_ibeam = 0;
- UInitCursor();
- }
- }
-
- }
-
- USuspendWindows()
- {
- WindowPtr fWindow;
- EventRecord myevent;
-
- fWindow = FrontWindow();
- if (fWindow != NULL) {
- HiliteWindow(fWindow, FALSE);
- myevent.modifiers = 0x00000000; /* Deactivate */
- myevent.message = (unsigned long)fWindow;
- wind_parse(myevent.message, &myevent, wActivate);
- }
- }
-
- UResumeWindows()
- {
- WindowPtr fWindow;
- EventRecord myevent;
-
- fWindow = FrontWindow();
- if (fWindow != NULL) {
- HiliteWindow(fWindow, TRUE);
- myevent.modifiers = 0x00000001; /* Activate */
- myevent.message = (unsigned long)fWindow;
- wind_parse(myevent.message, &myevent, wActivate);
- }
- }
-
-